/*
 * Pressure.m
 * This file is part of WX
 *
 * Copyright 2010-2013 Jason Coulls. All Rights Reserved.
 *
 * is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2 of the License.
 *
 * is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with . If not, see <http://www.gnu.org/licenses>.
 */

#import "Pressure.h"

#define kPASCALSPERINCH     3386.38866667

@implementation Pressure
@synthesize reading;
@synthesize pressureScale;
@synthesize tendency;

-(id) init
{
    self = [super init];
    //Create a default pressure instance.
    self.pressureScale = kPRESSUREKILOPASCALS;
    self.reading = 101.325;
    self.tendency = 0;
    return self;
}


-(double) pressureInPascals
{
    double returnValue = 0;
    
    if (self.pressureScale == kPRESSUREPASCALS) {
        returnValue = self.reading;
    
    } else if (self.pressureScale == kPRESSUREKILOPASCALS ) {
        returnValue = (self.reading * 1000);
        
    } else if (self.pressureScale == kPRESSUREMILLIBARS ||
               self.pressureScale == kPRESSUREHECTOPASCALS ) {
        returnValue = (self.reading / 10);
        
    } else if (self.pressureScale == kPRESSUREINCHESOFMERCURY) {
        returnValue = (self.reading * kPASCALSPERINCH);

    }
    
    return returnValue;
}


-(double) pressureInKilopascals
{
    double returnValue = 0;
    
    if (self.pressureScale == kPRESSUREPASCALS) {
        returnValue = (self.reading / 1000);
        
    } else if (self.pressureScale == kPRESSUREKILOPASCALS ) {
        returnValue = self.reading;
        
    } else if (self.pressureScale == kPRESSUREMILLIBARS ||
               self.pressureScale == kPRESSUREHECTOPASCALS ) {
        returnValue = (self.reading / 10);
        
    } else if (self.pressureScale == kPRESSUREINCHESOFMERCURY) {
        returnValue = (self.reading * kPASCALSPERINCH) / 1000;
        
    }
    
    return returnValue;

}


-(double) pressureInMillibars
{
    double returnValue = 0;
    
    if (self.pressureScale == kPRESSUREPASCALS) {
        returnValue = (self.reading * 0.01);
        
    } else if (self.pressureScale == kPRESSUREKILOPASCALS ) {
        returnValue = (self.reading * 0.1);
        
    } else if (self.pressureScale == kPRESSUREMILLIBARS ||
               self.pressureScale == kPRESSUREHECTOPASCALS ) {
        returnValue = self.reading;
        
    } else if (self.pressureScale == kPRESSUREINCHESOFMERCURY) {
        returnValue = (self.reading * kPASCALSPERINCH) / 100;
        
    }
    
    return returnValue;
    
}

-(double) pressureInHectopascals
{
    double returnValue = 0;
    
    if (self.pressureScale == kPRESSUREPASCALS) {
        returnValue = (self.reading / 100);
        
    } else if (self.pressureScale == kPRESSUREKILOPASCALS ) {
        returnValue = (self.reading * 0.1);
        
    } else if (self.pressureScale == kPRESSUREMILLIBARS ||
               self.pressureScale == kPRESSUREHECTOPASCALS ) {
        returnValue = self.reading;
        
    } else if (self.pressureScale == kPRESSUREINCHESOFMERCURY) {
        returnValue = (self.reading * kPASCALSPERINCH) / 10;
        
    }
    
    return returnValue;
}

-(double) pressureInInchesOfMercury
{
    double returnValue = 0;
    
    if (self.pressureScale == kPRESSUREPASCALS) {
        returnValue = (self.reading / kPASCALSPERINCH);
        
    } else if (self.pressureScale == kPRESSUREKILOPASCALS ) {
        returnValue = (self.reading * kPASCALSPERINCH) / 1000;
        
    } else if (self.pressureScale == kPRESSUREMILLIBARS ||
               self.pressureScale == kPRESSUREHECTOPASCALS ) {
        returnValue = (self.reading * kPASCALSPERINCH) / 100;
        
    } else if (self.pressureScale == kPRESSUREINCHESOFMERCURY) {
        returnValue = self.reading;
        
    }
    
    return returnValue;
}


@end
